package AcWing周赛;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: a
 * Date: 2022-09-10
 * Time: 18:56
 */
public class Demo68_1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int T = scanner.nextInt();
        while(T-- > 0){
            String s = scanner.next();
            int len = s.length();
            int n = 0;
            int m = 0;
            for(int i = 0; i < len; i++){
                if(s.charAt(i) == '1'){
                    n = i;
                    break;
                }
            }
            for(int i = len - 1; i >= 0; i--){
                if(s.charAt(i) == '1'){
                    m = i;
                    break;
                }
            }
            int count = 0;
            for(int i = n; i < m; i++){
                if(s.charAt(i) == '0'){
                    count++;
                }
            }
            System.out.println(count);
        }
    }
}
